var api = require('../../../util/api.js');

Page({
    data: {
        index: 0,
        rules: []
    },
    onLoad: function (options) {
        var _this = this;
        _this.setData({
            page: api.page(20),
            dataList: [],
            params: {
                examineId: api.chain().examineId
            },
            examineName: api.chain().examineName,
            rules: [{
                    id: 1,
                    rulesItem: "现场管理考核"
                },
                {
                    id: 2,
                    rulesItem: "综合考核"
                },
                {
                    id: 3,
                    rulesItem: "防火防爆"
                },
                {
                    id: 4,
                    rulesItem: "劳动纪律"
                },
                {
                    id: 5,
                    rulesItem: "监督互评"
                },
                {
                    id: 6,
                    rulesItem: "施工单位评分"
                },
                {
                    id: 7,
                    rulesItem: "整改单份数"
                },
                {
                    id: 8,
                    rulesItem: "问题数量"
                },
                {
                    id: 9,
                    rulesItem: "罚款单份数"
                }
            ]
        });
        _this.onReachBottom();
    },
    onReachBottom() {
        var n = this.data.rules[this.data.index].id;
        this.getItemAvgRanking(n);
    },
    PickerChange: function (t) {
        var n = this.data.rules[t.detail.value].id;
        this.setData({
            index: t.detail.value,
            page: api.page(20),
            dataList: []
        })
        this.getItemAvgRanking(n);
    },
    getItemAvgRanking: function (n) {
        var filed = ''
        switch (n) {
            case 1:
                filed = 'xcglTotal'
                break;
            case 2:
                filed = 'zhkhTotal'
                break;
            case 3:
                filed = 'fhfbTotal'
                break;
            case 4:
                filed = 'ldjlTotal'
                break;
            case 5:
                filed = 'jdhpTotal'
                break;
            case 6:
                filed = 'sgdwpfTotal'
                break;
            case 7:
                filed = 'zgd'
                break;
            case 8:
                filed = 'wt'
                break;
            case 9:
                filed = 'fkd'
                break;
            default:
                break;
        }
        var _this = this;
        var params = _this.data.params;
        var page = _this.data.page;
        api.get(`${api.ip}zjjd/${filed}/list`, params, page).then(res => {
            page.setTotal(res.total);
            if (res.rows.length == 0) {
                this.setData({
                    hasData: false
                })
            } else {
                _this.setData({
                    hasData: true,
                    dataList: _this.data.dataList.concat(res.rows)
                });
            }
        })
    }
});